package com.rc.evcharger.service.elec;

import com.rc.evcharger.common.constant.SocketConstant;
import com.rc.evcharger.mapper.elec.ElecStationMapper;
import com.rc.evcharger.model.elec.ElecStation;
import com.rc.evcharger.service.tenant.TenantSettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by sven on 2019/09/23.
 */
@Service
public class ElecStationServiceImpl implements ElecStationService {

    @Autowired
    private ElecStationMapper elecStationMapper;

    @Autowired
    private TenantSettingService tenantSettingService;

    @Override
    public ElecStationMapper getMapper() {
        return elecStationMapper;
    }

    /**
     * 获取站点预设soc阈值
     *
     * @param elecStationId
     * @param type          0.soc 1.电池温度
     * @return
     */
    @Override
    public Integer selectLimitSoc(Long elecStationId, int type) {
        ElecStation elecStation = elecStationMapper.selectByPrimaryKey(elecStationId);
        if (elecStation == null) {
            return null;
        }
        //是否开放soc、温度阈值功能
        boolean open = tenantSettingService.query_open_charge_limit_soc(elecStation.getTenantCode(),type);
        if (!open){
            return null;
        }

        if (type == SocketConstant.CON0) {
            return elecStation.getLimitSoc();
        } else {
            return elecStation.getLimitBatteryTemp();
        }
    }

    @Override
    public int selectOccupyStatusByelecStationId(Long elecStationId) {
        ElecStation elecStation = elecStationMapper.selectByPrimaryKey(elecStationId);
        if ("1".equals(elecStation.getOccupyStatus())){
            return 1;
        }
        return 0;
    }
}
